package com.example.demo.util;

import java.util.HashMap;
import java.util.Map;

public class ResolutionChecker {
    // 定义支持的分辨率及其对应的比例
    private static final Map<String, String> SUPPORTED_RESOLUTIONS = new HashMap<>();
    
    static {
        SUPPORTED_RESOLUTIONS.put("720x1280", "9:16");
        SUPPORTED_RESOLUTIONS.put("1280x720", "16:9");
        SUPPORTED_RESOLUTIONS.put("720x720", "1:1");
        SUPPORTED_RESOLUTIONS.put("720x960", "3:4");
        SUPPORTED_RESOLUTIONS.put("960x720", "4:3");
        SUPPORTED_RESOLUTIONS.put("1280x640", "2:1");
        SUPPORTED_RESOLUTIONS.put("1680x720", "21:9");
    }
    
    public static String checkResolution(int width, int height) throws IllegalArgumentException {
        String resolution = width + "x" + height;
        
        if (SUPPORTED_RESOLUTIONS.containsKey(resolution)) {
            return SUPPORTED_RESOLUTIONS.get(resolution);
        } else {
//            throw new IllegalArgumentException("不支持该分辨率: " + resolution);
            return "false";
        }
    }
    
    public static void main(String[] args) {
        // 测试用例
        try {
            System.out.println(checkResolution(720, 1280));  // 输出: 9:16
            System.out.println(checkResolution(1280, 720));  // 输出: 16:9
            System.out.println(checkResolution(720, 720));   // 输出: 1:1
            System.out.println(checkResolution(800, 600));   // 抛出异常
            if (checkResolution(800, 600).equals("false")) {
                System.out.println("不支持的分辨率");
            }
        } catch (IllegalArgumentException e) {
            System.err.println(e.getMessage());
        }
    }
}